CMAKE_MINIMUM_REQUIRED(VERSION 3.2.3 FATAL_ERROR)

PROJECT(TestJafSerialize)

file(GLOB_RECURSE Serialize_FILES 
	${PROJECT_SOURCE_DIR}/../JafSerialize/*.h 
	${PROJECT_SOURCE_DIR}/../JafSerialize/*.c 
	${PROJECT_SOURCE_DIR}/../JafSerialize/*.cpp)
file(GLOB_RECURSE code_FILES ${PROJECT_SOURCE_DIR}/*.h ${PROJECT_SOURCE_DIR}/*.c ${PROJECT_SOURCE_DIR}/*.cpp)

#message("Serialize_FILES = ${Serialize_FILES}")
#message("code_FILES = ${code_FILES}")
set(ALL_FILES 
    ${Serialize_FILES}
    ${code_FILES}
)

source_group(TREE ${CMAKE_SOURCE_DIR}/${SerializeInclude} FILES ${Serialize_FILES})
source_group(TREE ${CMAKE_SOURCE_DIR}/${PROJECT_NAME} FILES ${code_FILES})

AUX_SOURCE_DIRECTORY(. SRC_FILES)
ADD_EXECUTABLE(${PROJECT_NAME}
    ${ALL_FILES}
)

INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/..)
INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR})

#gtest
IF(${HOST_PLATFORM} STREQUAL PLATFORM_X86)
    SET(GTEST_ROOT "$ENV{GTEST_HOME_X86}")
ELSEIF(${HOST_PLATFORM} STREQUAL PLATFORM_X64)
    SET(GTEST_ROOT "$ENV{GTEST_HOME_X64}")
ENDIF()

INCLUDE_DIRECTORIES(${GTEST_ROOT}/include)
TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${GTEST_ROOT}/lib/gtestd.lib)

IF(MSVC)
    SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES COMPILE_FLAGS "/MP")
    CONFIGURE_FILE("${PROJECT_SOURCE_DIR}/../../other/VSUserTemplate.vcxproj.user" "${PROJECT_BINARY_DIR}/${PROJECT_NAME}.vcxproj.user")
    ADD_DEFINITIONS(-D_WIN32_WINNT=0x0601 -D_SCL_SECURE_NO_WARNINGS)
ENDIF()

IF(UNIX)
    SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fpic")
    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpic")
ENDIF()
